/*
 * Created by JFormDesigner on Tue Nov 20 09:22:46 GFT 2012
 */

package com.citi.xylophone.phoneEmulator.view;

import java.io.FileNotFoundException;

import javax.swing.*;

import com.citi.xylophone.phoneEmulator.factory.FactoryInitConfig;
import com.citi.xylophone.phoneEmulator.global.GlobalSwap;
import com.citi.xylophone.phoneEmulator.model.xml.Config;
import com.citi.xylophone.phoneEmulator.model.xml.ConfigSource;
import com.citi.xylophone.phoneEmulator.view.listener.ButtonCallListener;
import com.citi.xylophone.phoneEmulator.view.listener.ButtonConectListener;
import com.citi.xylophone.phoneEmulator.view.listener.ButtonDialListener;
import com.citi.xylophone.phoneEmulator.view.listener.ButtonSendListener;
import com.jgoodies.forms.layout.*;

/**
 * @author Nicolas Matos
 */
public class MainPanelview extends JPanel {

	private static final long serialVersionUID = -4363373980861469788L;
	public MainPanelview() throws FileNotFoundException {
		initComponents();
	}

	public JTextField getTextField1() {
		return textField1;
	}

	private void initComponents() throws FileNotFoundException {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Nicolas Matos
		label5 = new JLabel();
		separator3 = new JSeparator();
		button1 = new JButton();
		button2 = new JButton();
		button3 = new JButton();
		button17 = new JButton();
		button18 = new JButton();
		button4 = new JButton();
		button5 = new JButton();
		button6 = new JButton();
		button14 = new JButton();
		button13 = new JButton();
		button7 = new JButton();
		button8 = new JButton();
		button9 = new JButton();
		button12 = new JButton();
		button19 = new JButton();
		button15 = new JButton();
		button20 = new JButton();
		button21 = new JButton();
		button22 = new JButton();
		button23 = new JButton();
		textField1 = new JTextField();
		button10 = new JButton();
		separator2 = new JSeparator();
		label3 = new JLabel();
		comboBox1 = new JComboBox();
		button11 = new JButton();
		separator4 = new JSeparator();
		label1 = new JLabel();
		comboBox3 = new JComboBox();
		separator1 = new JSeparator();
		label4 = new JLabel();
		comboBox2 = new JComboBox();
		button16 = new JButton();
		CellConstraints cc = new CellConstraints();

		//======== this ========

		// JFormDesigner evaluation mark
		setBorder(new javax.swing.border.CompoundBorder(
			new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
				"", javax.swing.border.TitledBorder.CENTER,
				javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
				java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

		setLayout(new FormLayout(
			"5*(default, $lcgap), 51dlu, $lcgap, 15dlu:grow",
			"14*(default, $lgap), default"));

		//---- label5 ----
		label5.setText("Xylophone Virtual Phone");
		add(label5, cc.xywh(3, 3, 9, 1, CellConstraints.CENTER, CellConstraints.DEFAULT));
		add(separator3, cc.xywh(3, 5, 9, 1));

		//---- button1 ----
		button1.setText("1");
		add(button1, cc.xy(3, 7));

		//---- button2 ----
		button2.setText("2");
		add(button2, cc.xy(5, 7));

		//---- button3 ----
		button3.setText("3");
		add(button3, cc.xy(7, 7));

		//---- button17 ----
		button17.setText("call");
		add(button17, cc.xy(9, 7));

		//---- button18 ----
		button18.setText("call end");
		add(button18, cc.xy(11, 7));

		//---- button4 ----
		button4.setText("4");
		add(button4, cc.xy(3, 9));

		//---- button5 ----
		button5.setText("5");
		add(button5, cc.xy(5, 9));

		//---- button6 ----
		button6.setText("6");
		add(button6, cc.xy(7, 9));

		//---- button14 ----
		button14.setText("no match");
		add(button14, cc.xy(9, 9));

		//---- button13 ----
		button13.setText("no input");
		add(button13, cc.xy(11, 9));

		//---- button7 ----
		button7.setText("7");
		add(button7, cc.xy(3, 11));

		//---- button8 ----
		button8.setText("8");
		add(button8, cc.xy(5, 11));

		//---- button9 ----
		button9.setText("9");
		add(button9, cc.xy(7, 11));

		//---- button12 ----
		button12.setText("stop");
		add(button12, cc.xy(9, 11));

		//---- button19 ----
		button19.setText("show log");
		add(button19, cc.xy(11, 11));

		//---- button15 ----
		button15.setText("*");
		add(button15, cc.xy(3, 13));

		//---- button20 ----
		button20.setText("0");
		add(button20, cc.xy(5, 13));

		//---- button21 ----
		button21.setText("#");
		add(button21, cc.xy(7, 13));

		//---- button22 ----
		button22.setText("repeat");
		add(button22, cc.xy(9, 13));

		//---- button23 ----
		button23.setText("tbd");
		add(button23, cc.xy(11, 13));
		add(textField1, cc.xywh(3, 15, 5, 1));

		//---- button10 ----
		button10.setText("send / go");
		add(button10, cc.xywh(9, 15, 3, 1));
		add(separator2, cc.xywh(3, 17, 9, 1));

		//---- label3 ----
		label3.setText("Server");
		add(label3, cc.xy(3, 19));
		add(comboBox1, cc.xywh(5, 19, 5, 1));

		//---- button11 ----
		button11.setText("connect");
		add(button11, cc.xy(11, 19));
		add(separator4, cc.xywh(3, 21, 9, 1));

		//---- label1 ----
		label1.setText("Dnis");
		add(label1, cc.xy(3, 23));
		add(comboBox3, cc.xywh(5, 23, 5, 1));
		add(separator1, cc.xywh(2, 25, 10, 1));

		//---- label4 ----
		label4.setText("Scripts");
		add(label4, cc.xy(3, 27));
		add(comboBox2, cc.xywh(5, 27, 5, 1));

		//---- button16 ----
		button16.setText("execute");
		add(button16, cc.xy(11, 27));
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
		
		
		button10.addActionListener(new ButtonSendListener(this));
		button11.addActionListener(new ButtonConectListener(this));
		button17.addActionListener(new ButtonCallListener(this));		
		button1.addActionListener(new ButtonDialListener(this));
		button2.addActionListener(new ButtonDialListener(this));
		button3.addActionListener(new ButtonDialListener(this));
		button4.addActionListener(new ButtonDialListener(this));
		button5.addActionListener(new ButtonDialListener(this));
		button6.addActionListener(new ButtonDialListener(this));
		button7.addActionListener(new ButtonDialListener(this));
		button8.addActionListener(new ButtonDialListener(this));
		button9.addActionListener(new ButtonDialListener(this));
		button15.addActionListener(new ButtonDialListener(this));
		button20.addActionListener(new ButtonDialListener(this));
		button21.addActionListener(new ButtonDialListener(this));
		
		
		config = FactoryInitConfig.getConfig("robot-config.xml");
		GlobalSwap.setConfig(config);
		for (ConfigSource configSource:config.getDestinationList()){
			comboBox1.addItem(configSource.getName());
		}
		
		
		comboBox2.setEnabled(false);
		comboBox3.setEnabled(false);
		button16.setEnabled(false);
		
		disableDial();
		disableActions();
	}
	
	public JComboBox getComboBox3() {
		return comboBox3;
	}

	public void disableActions(){
		
		button17.setEnabled(false);
		button18.setEnabled(false);
		button14.setEnabled(false);
		button13.setEnabled(false);
		button12.setEnabled(false);
		button19.setEnabled(false);
		button22.setEnabled(false);
		button23.setEnabled(false);
		
	}
	
	public JButton getButton17() {
		return button17;
	}

	public void enabledActions(){
		
		button17.setEnabled(true);
		button18.setEnabled(true);
		button14.setEnabled(true);
		button13.setEnabled(true);
		button12.setEnabled(true);
		button19.setEnabled(true);
		button22.setEnabled(true);
		button23.setEnabled(true);
		
	}
	
	public void disableDial(){
		
		button1.setEnabled(false);
		button2.setEnabled(false);
		button3.setEnabled(false);
		button4.setEnabled(false);
		button5.setEnabled(false);
		button6.setEnabled(false);
		button7.setEnabled(false);
		button8.setEnabled(false);
		button9.setEnabled(false);
		button15.setEnabled(false);
		button20.setEnabled(false);
		button21.setEnabled(false);
		textField1.setEnabled(false);
		textField1.setText("");
		button10.setEnabled(false);
	}
	
	public void enabledDial(){
		
		button1.setEnabled(true);
		button2.setEnabled(true);
		button3.setEnabled(true);
		button4.setEnabled(true);
		button5.setEnabled(true);
		button6.setEnabled(true);
		button7.setEnabled(true);
		button8.setEnabled(true);
		button9.setEnabled(true);
		button15.setEnabled(true);
		button20.setEnabled(true);
		button21.setEnabled(true);
		textField1.setEnabled(true);
		button10.setEnabled(true);
	}

	public JButton getButton16() {
		return button16;
	}

	public void setButton16(JButton button16) {
		this.button16 = button16;
	}

	public JComboBox getComboBox1() {
		return comboBox1;
	}

	public JButton getButton11() {
		return button11;
	}

	public JComboBox getComboBox2() {
		return comboBox2;
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Nicolas Matos
	private JLabel label5;
	private JSeparator separator3;
	private JButton button1;
	private JButton button2;
	private JButton button3;
	private JButton button17;
	private JButton button18;
	private JButton button4;
	private JButton button5;
	private JButton button6;
	private JButton button14;
	private JButton button13;
	private JButton button7;
	private JButton button8;
	private JButton button9;
	private JButton button12;
	private JButton button19;
	private JButton button15;
	private JButton button20;
	private JButton button21;
	private JButton button22;
	private JButton button23;
	private JTextField textField1;
	private JButton button10;
	private JSeparator separator2;
	private JLabel label3;
	private JComboBox comboBox1;
	private JButton button11;
	private JSeparator separator4;
	private JLabel label1;
	private JComboBox comboBox3;
	private JSeparator separator1;
	private JLabel label4;
	private JComboBox comboBox2;
	private JButton button16;
	// JFormDesigner - End of variables declaration  //GEN-END:variables
	private Config config;
	
	public void eventFinishAudios() throws Exception {
		GlobalSwap.getCoreExecutor().getFinishAudio(textField1.getText());
	}
}
